package de.haw.HES.Vertrieb;

import java.io.Serializable;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import de.haw.HES.Warenmanagement.Produkt;
import de.haw.HES.base.FachObjekt;

@Entity
@Table(name = "Menge")
@AssociationOverrides({
		@AssociationOverride(name = "pk.angebot", joinColumns = @JoinColumn(name = "angebot_id")),
		@AssociationOverride(name = "pk.produkt", joinColumns = @JoinColumn(name = "produkt_id")) })
public class Menge implements Serializable,FachObjekt {

	private MengePK pk = new MengePK();
	private int menge;

	@EmbeddedId
	public MengePK getPk() {
		return pk;
	}

	public void setPk(MengePK mengePK) {
		this.pk = mengePK;
	}

	@Transient
	public Angebot getAngebot() {
		return getPk().getAngebot();
	}

	public void setAngebot(Angebot angebot) {
		getPk().setAngebot(angebot);
	}

	@Transient
	public Produkt getProdukt() {
		return getPk().getProdukt();
	}

	public void setProdukt(Produkt produkt) {
		getPk().setProdukt(produkt);
	}

	@Column(nullable = false)
	public int getMenge() {
		return menge;
	}

	public void setMenge(int menge) {
		this.menge = menge;
	}

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Menge that = (Menge) o;

		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;

		return true;
	}

	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}

}
